import NewClass from "./CaiPengzhuang";
import GameData from "./GameData";

/** 全局工具类 */
export default class vv {

    /** 上一次显示提示的时间 */
    static showTipTime: Date = new Date();

    /** 添加按钮点击处理 */
    static btnClick(node: cc.Node, cb?: Function, noScale?: boolean, noPlayAudio?: boolean) {
        node.on('touchend', (event) => {
            if (cb) cb(event);
           // if (!noPlayAudio)  SoundManager.Instance.PlayEffect("click_sound");
           
        });
    }


      /** 提示框 font:显示的文字 */
      static showTip(font: string) {
        let time: Date = new Date();
        if (time.getTime() - this.showTipTime.getTime() < 800) return;
        this.showTipTime = time;

        cc.loader.loadRes("Prefab/tip", (err, prefab) => {
            if (err) {
                cc.log("加载预制体出错: " + err);
                return;
            }
            let node = cc.instantiate(prefab);
            node.x = cc.winSize.width / 2;
            node.y = cc.winSize.height / 2;
            node.getChildByName('tip').getComponent(cc.Label).string = font;
            node.parent = cc.director.getScene();

            //this.dynamicFrameRate(3);//动态调整游戏帧率
            node.runAction(cc.sequence(
                cc.moveBy(0.3, 0, 60).easing(cc.easeOut(0.5)),
                cc.delayTime(2),
                cc.fadeOut(0.6),
                cc.callFunc(() => {
                    node.destroy();
                })
            ));
        });
    }

     /**通过url设置本地图片 */
     /**SetImageByLocalUrl("Sprite/D2_fuyang",sprite3); */
     static SetImageByLocalUrl(url:string,node:cc.Node)
     {
        cc.loader.loadRes(url,  cc.SpriteFrame,(err, frame) =>{
            if(err)
            {
                return;
            } 
            if(node!=null)
            {
                var w = node.width;
                var h = node.height;
                node.getComponent(cc.Sprite).spriteFrame = frame;
                //node.width = w;
               // node.height = h;
            }
            
        })
    }
}
    